1260A - Heating - CodeForces Solution


math *1000

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
	c,s=map(int,input().split())
	d=s//c
	rem=s%c
	print(rem*(d+1)*(d+1)+(c-rem)*d*d)

C++ Code:

#include <bits/stdc++.h>
#define pb push_back
#define int long long int
using namespace std;

int mod = 1000000007;

int apowb(int b, int p)
{
  int res = 1;
  while (p)
  {
    if (p & 1)
    {
      res = (res * b) % mod;
    }

    p = p / 2;
    b = (b * b) % mod;
  }
  return res;
}

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
  {
    int n;
    cin >> n;
    int x, y;
    for (int k = 0; k < n; k++)
    {
      cin >> y >> x;
      if (x < y)
        cout << x << endl;
      else
      {
        int q = x / y;
        int rem = x % y;
        int left = y - rem;
        int res = 0;
        for (int i = 0; i < left; i++)
        {
          res += apowb(q, 2);
        }
        for (int i = 0; i < y - left; i++)
        {
          res += apowb(q + 1, 2);
        }
        cout << res << endl;
      }
    }
  }
  return (0);
}


Comments

Submit
0 Comments
More Questions

747A - Display Size
285A - Slightly Decreasing Permutations
515C - Drazil and Factorial
1151E - Number of Components
1151F - Sonya and Informatics
556A - Case of the Zeros and Ones
867A - Between the Offices
1569A - Balanced Substring
260A - Adding Digits
1698C - 3SUM Closure
1029B - Creating the Contest
1421A - XORwice
1029A - Many Equal Substrings
1675D - Vertical Paths
1271C - Shawarma Tent
805A - Fake NP
1163A - Eating Soup
787A - The Monster
807A - Is it rated
1096A - Find Divisible
1430C - Numbers on Whiteboard
1697B - Promo
208D - Prizes Prizes more Prizes
659A - Round House
1492C - Maximum width
171B - Star
1512B - Almost Rectangle
831B - Keyboard Layouts
814A - An abandoned sentiment from past
268C - Beautiful Sets of Points